package com.njbw.design_pattern.created.prototype.deepCopy;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 促销规则
 * String 是不可变对象，直接赋值即可
 *
 * @author 黄侯淳
 * @since JDK 1.8
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PromotionRule implements Cloneable, Serializable {

    /**
     * 促销类型
     */
    private String type;

    /**
     * 折扣/优惠力度
     */
    private double discount;

    /**
     * 促销产品
     */
    private Product product;

    @Override
    public PromotionRule clone() {
        try {
            PromotionRule cloned = (PromotionRule) super.clone();
            // 深拷贝产品对象
            if (this.product != null) {
                cloned.setProduct(this.product.clone());
            }
            return cloned;
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }
    }
}
